﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using CRM.Web.ServiceGIS;
using CRM.BLL;
using CRM.Entity;
using DP.Common;

namespace CRM.Web.Common
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class GISSearch1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string url = String.Empty;
            string vinCode = string.Empty;
            try
            {
                Page page = HttpContext.Current.Handler as Page;
                T_CONFIG_BLL configBll = new T_CONFIG_BLL();
                vinCode = (HttpContext.Current.Request.QueryString["VINCODE"] == null) ? "" : HttpContext.Current.Request.QueryString["VINCODE"].ToString();
                url = configBll.GetCacheValueByName(page, "GISWebServices");
                if (String.IsNullOrEmpty(url))
                {
                    url = "http://120.192.187.243:8081/machnService.jws?wsdl";
                }
                BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
                EndpointAddress endpointAddress = new EndpointAddress(url);
                machnServiceClient serviceClient = new machnServiceClient(binding, endpointAddress);
                string address = serviceClient.getLocation(vinCode);
                context.Response.ContentType = "text/plain";
                context.Response.Write(address);
                LogHelper.WriteLog("GPS_Success", String.Format("VinCode:{1} -- Url:{2} -- Address:{0}", address, vinCode, url));

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GPS_Exception", String.Format("VinCode:{1} -- Url:{2} -- Message:{0}", ex.Message, vinCode, url));
                
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
